//
//  YBCodeSortView.m
//  Cocoachina
//
//  Created by 游兵 on 2017/9/16.
//  Copyright © 2017年 YBing. All rights reserved.
//

#import "YBCodeSortView.h"

@implementation YBCodeSortView

+ (instancetype)sortViewWithFrame:(CGRect)frame didClickedBlock:(void (^)(NSInteger))didClickedBlock
{
    YBCodeSortView *view = [[[NSBundle mainBundle] loadNibNamed:@"YBCodeSortView" owner:nil options:nil] lastObject];
    view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    view.frame = frame;
    view.didClickedBlock = didClickedBlock;
    return view;
}

- (IBAction)click:(UIButton *)sender {
    if (sender.selected) return;
    for (int i = 0; i<3; i++) {
        UIButton *btn = [self viewWithTag:i+1];
        btn.selected = NO;
    }
    sender.selected = YES;
    if (self.didClickedBlock) {
        self.didClickedBlock(sender.tag-1);
    }
}

@end
